


#ifndef	__TL_LOG_H__
#define __TL_LOG_H__

#include "common.h"
#include "pin.h"
#include "sys_console.h"
#include "app_cfg.h"
#include "app_spi.h"
#include "app_init.h"
#include "app_factory.h"

#define	MaintenanceLogMode				1	// 0 Log is invalid
#define	CHRLogMode						0




#define		MaintenanceServiceID		10

#define MAINTENANCE_LOG_LENGTH			5
#define CHR_LOG_LENGTH					10			//16


#define 	LOG_INDEX_ADDR   		0x31000
#define 	LOG_ADDR   		    	0x32000


#define	LOG_SUCCESS  					1
#define	LOG_FAIL    					0

#define	MAINTENANCE_LOG_DATA_CHECK		0x55000000
#define	CHR_LOG_DATA_CHECK				0xAA000000

#define	eeprom_log_evt_index_addr		0x0000
#define	eeprom_log_byte_length_addr		0x0004
#define	eeprom_log_evt_baseaddr			LOG_ADDR//0x000c


//#define	Max_EEPROM_VOLUME				0x20000-eeprom_log_evt_baseaddr
#define	Max_EEPROM_VOLUME				0x40000-LOG_ADDR-MAINTENANCE_LOG_LENGTH

#define	Max_FLASH_VOLUME				0x40000-LOG_ADDR

extern uint32_t log_byte_length;

extern uint8_t  flash_log_flag;
extern volatile uint32_t flash_log_tiner_tick;

void log_init(void);
uint8_t set_log_evt_index(uint32_t index);
uint32_t get_log_evt_index(void);
uint8_t set_log_byte_length(uint32_t len);
uint32_t get_log_byte_length(void);

void rec_single_evt_test(uint8_t serid,uint8_t cmdid,uint8_t type,uint8_t len,uint8_t val);
void task_log_notify_test(void);

void rec_single_evt_CHR(uint8_t cmdid,uint8_t info1,uint8_t info2,uint8_t info3,uint8_t info4);
void task_log_notify_CHR(void);


 extern uint32_t	log_evt_index;

#define FM24C1024_slave_id   0xa0


#define FM24C1024_IIC_8BITS_WRITE_ADDR  0xa0
#define FM24C1024_IIC_8BITS_READ_ADDR   0xa1


#define FM24C1024_IIC_WRITE_ADDRESS  FM24C1024_IIC_8BITS_WRITE_ADDR
#define FM24C1024_IIC_READ_ADDRESS   FM24C1024_IIC_8BITS_READ_ADDR


#define FLASH_EVT_ADDR					0x04
#define FLASH_EVT_BLOCK_CNT				4
#define EVT_CNT_PER_BLOCK				(1000008/12)
#define EVT_CNT_IN_FLASH_MAX			(EVT_CNT_PER_BLOCK)
#define EVT_CNT_IN_RAM					77056

typedef struct{
	uint8_t  pri;
	uint8_t  evt;
	uint16_t sub;
}rm_evt;

typedef struct{
	uint32_t	time;
	uint32_t	index;				// 0x00000001~0xfffffffe
	rm_evt evt;
}rm_log_event;

#define LOG_LVL_HIGH_PRI		0
#define LOG_LVL_LOW_PRI			1

#define REMOTE_EVT_PWR_OFF				0x01
#define REMOTE_EVT_ID					0x02
#define REMOTE_EVT_WTD					0x03
#define REMOTE_EVT_PAIRING				0x04
#define REMOTE_EVT_NFC					0x05
#define REMOTE_EVT_RE_CONN				0x06
#define REMOTE_EVT_OTA_START			0x07
#define REMOTE_EVT_CHARGE_STA			0x08
#define REMOTE_EVT_BATT_VNT				0x09
#define REMOTE_EVT_TEMP_STA				0x0a
#define REMOTE_EVT_TP_STA				0x0b
#define REMOTE_EVT_IIC_STA				0x0c
#define REMOTE_EVT_CHARGEREQUST_STA		0x0d
#define REMOTE_EVT_MCUINFO_STA			0x0e
#define REMOTE_EVT_CHARGERINFO			0x0f
#define REMOTE_EVT_WIRELESSIC_INFO   	0x10
#define REMOTE_EVT_TP_FWVERSION   		0x12
#define REMOTE_MAC_ADDRESS				0x99

#define REMOTE_TP_FW_UPDATA   			0x13
#define REMOTE_terminate_reason	   		0x14
#define REMOTE_MCU_STATUS		   		0x15
#define REMOTE_EVT_GSENSOR_STA  		0x16
#define REMOTE_EVT_SLEEP_STA  			0x17
#define REMOTE_PAD_LCD_STA  			0x18
#define REMOTE_PAD_COVER_STA  			0x19
#define REMOTE_UART_SEND_STA  			0x1A
#define REMOTE_UART_SEND_TEST  			0x1B
#define REMOTE_UART_SEND_TEST_NUM  		0x1C

#define REMOTE_KB_LOCK_STA  			0x1D
#define REMOTE_PAD_TIME					0x1E

#define	LOG_FLAG_ADVTIMEOUT		0x00000001
#define	LOG_FLAG_ADV			0x00000001




extern uint32_t LogInsertFlag;





 extern uint8_t log_push_notify_en;
 extern uint32_t	tick_log_notify_start;
extern void set_log_notify_en(uint8_t en);
extern void set_chr_notify_en(uint8_t en);
extern int log_ctrl_callback(uint8_t *dat);
extern int chr_ctrl_callback(uint16_t connHandle,uint8_t *dat);

extern void rec_single_evt(uint8_t *p);
extern void task_log_pwr_init();
extern void task_log_notify();

extern void log_pro( void * p );




extern void app_flash_log_timer_tick_0_1_ms_callback(void);




#endif
